<template>
  <div class="bg_box">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      status-icon
      :rules="rules"
      label-width="80px"
      class="login-ruleForm"
      hide-required-asterisk
      :show-message="false"
    >
      <div class="title">医卫融合系统</div>
      <el-form-item label="用户名" prop="userName" class="username">
        <el-input
          v-model="ruleForm.userName"
          type="text"
          placeholder="请输入登录账号"
          clearable
        ></el-input>
        <!-- <input type="text" v-model="ruleForm.username"> -->
      </el-form-item>
      <el-form-item label="密码" prop="passWord">
        <el-input
          v-model="ruleForm.passWord"
          type="password"
          autocomplete="off"
          placeholder="请输入登录密码"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item class="subBtn">
        <el-button
          type="primary"
          @keydown.native="loginIn"
          @click="submitForm"
          >登 录</el-button
        >
        <!-- <el-button type="primary" @click="submitSign"
          >注 册</el-button
        > -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import store from "@/store";
import { reactive, ref } from "vue";
import router from '@/router/index.js'

const ruleFormRef = ref()

const ruleForm = reactive({
  userName: "",
  passWord: "",
});
const rules = reactive({
  userName: [{ required: true, message: "请输入用户名", trigger: "blur" }],
  passWord: [{ required: true, message: "请输入密码", trigger: "blur" }],
});

const submitForm = async () => {
  // await ruleFormRef.value.validate((valid, fields) => {
  //   if (valid) {
  //     let params = {
  //       ...ruleForm,
  //     };
  //     store.dispatch("Login", params).then((res) => {
  //       router.push({ path: "/home" })
  //       document.removeEventListener("keydown", loginIn);
  //     });
  //   }
  // });
  router.push({ path: "/home" })
};

// const submitSign = async () => {
//   let params = {
//         ...ruleForm,
//       };

// }

const loginIn = (e) => {
  if (e.key === "Enter") {
    submitForm();
  }
};



document.addEventListener("keydown", loginIn);
</script>

<style scoped lang="scss">
.bg_box {
  height: 100%;
  width: 100%;
  background-image: url("~@/assets/image/bg.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  overflow: hidden;
  user-select: none;
  .login-ruleForm {
    width: 400px;
    margin-top: 240px;
    background-color: rgba(255, 255, 255, 0.2);
    padding: 20px;
    position: absolute;
    right: 160px;
    top: initial;
    border-radius: 5px;
    .title {
      margin-bottom: 15px;
      text-align: center;
      font-size: 20px;
      font-weight: bold;
      color: #000;
      letter-spacing: 2px;
    }
    ::v-deep .el-form-item__label {
      color: #fff;
    }
    .subBtn {
      margin-bottom: 10px;
      ::v-deep .el-form-item__content {
        .el-button {
          width: 100%;
        }
      }
    }
  }
}
</style>
